<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>

<title>EnableTransactionManagement (Spring Framework 5.0.2.RELEASE API)</title>
<meta name="date" content="2017-11-27">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
</head>
<body>
<script type="text/javascript">try{if(location.href.indexOf('is-external=true')==-1){parent.document.title="EnableTransactionManagement (Spring Framework 5.0.2.RELEASE API)";}}catch(err){}</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>

<div class="topNav"><a name="navbar.top">

</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">

</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-files/index-1.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage">Spring Framework</div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.html" title="class in org.springframework.transaction.annotation"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../org/springframework/transaction/annotation/Isolation.html" title="enum in org.springframework.transaction.annotation"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/springframework/transaction/annotation/EnableTransactionManagement.html" target="_top">Frames</a></li>
<li><a href="EnableTransactionManagement.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript">allClassesLink=document.getElementById("allclasses_navbar_top");if(window==top){allClassesLink.style.display="block";}else{allClassesLink.style.display="none";}</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.top">

</a></div>


<div class="header">
<div class="subTitle">org.springframework.transaction.annotation</div>
<h2 title="Annotation Type EnableTransactionManagement" class="title">Annotation Type EnableTransactionManagement</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>@Target(value=TYPE)
 @Retention(value=RUNTIME)
 @Documented
 <a href="../../../../org/springframework/context/annotation/Import.html" title="annotation in org.springframework.context.annotation">@Import</a>(<a href="../../../../org/springframework/context/annotation/Import.html#value--">value</a>=<a href="../../../../org/springframework/transaction/annotation/TransactionManagementConfigurationSelector.html" title="class in org.springframework.transaction.annotation">TransactionManagementConfigurationSelector.class</a>)
public @interface <span class="memberNameLabel">EnableTransactionManagement</span></pre>
<div class="block">Enables Spring's annotation-driven transaction management capability, similar to
the support found in Spring's <code>&lt;tx:*&gt;</code> XML namespace. To be used on
<a href="../../../../org/springframework/context/annotation/Configuration.html" title="annotation in org.springframework.context.annotation"><code>@Configuration</code></a>
classes as follows:
<pre class="code"> &#064;Configuration
 &#064;EnableTransactionManagement
 public class AppConfig {

     &#064;Bean
     public FooRepository fooRepository() {
         // configure and return a class having &#064;Transactional methods
         return new JdbcFooRepository(dataSource());
     }

     &#064;Bean
     public DataSource dataSource() {
         // configure and return the necessary JDBC DataSource
     }

     &#064;Bean
     public PlatformTransactionManager txManager() {
         return new DataSourceTransactionManager(dataSource());
     }
 }</pre>
<p>For reference, the example above can be compared to the following Spring XML
configuration:
<pre class="code"> <code>&lt;beans&gt;

     &lt;tx:annotation-driven/&gt;

     &lt;bean id="fooRepository" class="com.foo.JdbcFooRepository"&gt;
         &lt;constructor-arg ref="dataSource"/&gt;
     &lt;/bean&gt;

     &lt;bean id="dataSource" class="com.vendor.VendorDataSource"/&gt;

     &lt;bean id="transactionManager" class="org.sfwk...DataSourceTransactionManager"&gt;
         &lt;constructor-arg ref="dataSource"/&gt;
     &lt;/bean&gt;

 &lt;/beans&gt;
 </code></pre>
In both of the scenarios above, <code>@EnableTransactionManagement</code> and <code>&lt;tx:annotation-driven/&gt;</code> are responsible for registering the necessary Spring
components that power annotation-driven transaction management, such as the
TransactionInterceptor and the proxy- or AspectJ-based advice that weave the
interceptor into the call stack when <code>JdbcFooRepository</code>'s <code>@Transactional</code>
methods are invoked.
<p>A minor difference between the two examples lies in the naming of the <code>PlatformTransactionManager</code> bean: In the <code>@Bean</code> case, the name is
<em>"txManager"</em> (per the name of the method); in the XML case, the name is
<em>"transactionManager"</em>. The <code>&lt;tx:annotation-driven/&gt;</code> is hard-wired to
look for a bean named "transactionManager" by default, however
<code>@EnableTransactionManagement</code> is more flexible; it will fall back to a by-type
lookup for any <code>PlatformTransactionManager</code> bean in the container. Thus the name
can be "txManager", "transactionManager", or "tm": it simply does not matter.
<p>For those that wish to establish a more direct relationship between
<code>@EnableTransactionManagement</code> and the exact transaction manager bean to be used,
the <a href="../../../../org/springframework/transaction/annotation/TransactionManagementConfigurer.html" title="interface in org.springframework.transaction.annotation"><code>TransactionManagementConfigurer</code></a> callback interface may be implemented -
notice the <code>implements</code> clause and the <code>@Override</code>-annotated method below:
<pre class="code"> &#064;Configuration
 &#064;EnableTransactionManagement
 public class AppConfig implements TransactionManagementConfigurer {

     &#064;Bean
     public FooRepository fooRepository() {
         // configure and return a class having &#064;Transactional methods
         return new JdbcFooRepository(dataSource());
     }

     &#064;Bean
     public DataSource dataSource() {
         // configure and return the necessary JDBC DataSource
     }

     &#064;Bean
     public PlatformTransactionManager txManager() {
         return new DataSourceTransactionManager(dataSource());
     }

     &#064;Override
     public PlatformTransactionManager annotationDrivenTransactionManager() {
         return txManager();
     }
 }</pre>
This approach may be desirable simply because it is more explicit, or it may be
necessary in order to distinguish between two <code>PlatformTransactionManager</code> beans
present in the same container. As the name suggests, the
<code>annotationDrivenTransactionManager()</code> will be the one used for processing
<code>@Transactional</code> methods. See <a href="../../../../org/springframework/transaction/annotation/TransactionManagementConfigurer.html" title="interface in org.springframework.transaction.annotation"><code>TransactionManagementConfigurer</code></a> Javadoc
for further details.
<p>The <a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#mode--"><code>mode()</code></a> attribute controls how advice is applied: If the mode is
<a href="../../../../org/springframework/context/annotation/AdviceMode.html#PROXY"><code>AdviceMode.PROXY</code></a> (the default), then the other attributes control the behavior
of the proxying. Please note that proxy mode allows for interception of calls through
the proxy only; local calls within the same class cannot get intercepted that way.
<p>Note that if the <a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#mode--">mode()</a> is set to <a href="../../../../org/springframework/context/annotation/AdviceMode.html#ASPECTJ"><code>AdviceMode.ASPECTJ</code></a>, then the
value of the <a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#proxyTargetClass--"><code>proxyTargetClass()</code></a> attribute will be ignored. Note also that in
this case the <code>spring-aspects</code> module JAR must be present on the classpath, with
compile-time weaving or load-time weaving applying the aspect to the affected classes.
There is no proxy involved in such a scenario; local calls will be intercepted as well.</div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>3.1</dd>
<dt><span class="simpleTagLabel">Author:</span></dt>
<dd>Chris Beams, Juergen Hoeller</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../org/springframework/transaction/annotation/TransactionManagementConfigurer.html" title="interface in org.springframework.transaction.annotation"><code>TransactionManagementConfigurer</code></a>,
<a href="../../../../org/springframework/transaction/annotation/TransactionManagementConfigurationSelector.html" title="class in org.springframework.transaction.annotation"><code>TransactionManagementConfigurationSelector</code></a>,
<a href="../../../../org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.html" title="class in org.springframework.transaction.annotation"><code>ProxyTransactionManagementConfiguration</code></a>,
<a href="../../../../org/springframework/transaction/aspectj/AspectJTransactionManagementConfiguration.html" title="class in org.springframework.transaction.aspectj"><code>AspectJTransactionManagementConfiguration</code></a></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">

<ul class="blockList">
<li class="blockList"><a name="annotation.type.optional.element.summary">

</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Optional Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code><a href="../../../../org/springframework/context/annotation/AdviceMode.html" title="enum in org.springframework.context.annotation">AdviceMode</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#mode--">mode</a></span></code>
<div class="block">Indicate how transactional advice should be applied.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#order--">order</a></span></code>
<div class="block">Indicate the ordering of the execution of the transaction advisor
when multiple advices are applied at a specific joinpoint.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#proxyTargetClass--">proxyTargetClass</a></span></code>
<div class="block">Indicate whether subclass-based (CGLIB) proxies are to be created (<code>true</code>) as
opposed to standard Java interface-based proxies (<code>false</code>).</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">

<ul class="blockList">
<li class="blockList"><a name="annotation.type.element.detail">

</a>
<h3>Element Detail</h3>
<a name="proxyTargetClass--">

</a>
<ul class="blockList">
<li class="blockList">
<h4>proxyTargetClass</h4>
<pre>public abstract&nbsp;boolean&nbsp;proxyTargetClass</pre>
<div class="block">Indicate whether subclass-based (CGLIB) proxies are to be created (<code>true</code>) as
opposed to standard Java interface-based proxies (<code>false</code>). The default is
<code>false</code>. <strong>Applicable only if <a href="../../../../org/springframework/transaction/annotation/EnableTransactionManagement.html#mode--"><code>mode()</code></a> is set to
<a href="../../../../org/springframework/context/annotation/AdviceMode.html#PROXY"><code>AdviceMode.PROXY</code></a></strong>.
<p>Note that setting this attribute to <code>true</code> will affect <em>all</em>
Spring-managed beans requiring proxying, not just those marked with
<code>@Transactional</code>. For example, other beans marked with Spring's
<code>@Async</code> annotation will be upgraded to subclass proxying at the same
time. This approach has no negative impact in practice unless one is explicitly
expecting one type of proxy vs another, e.g. in tests.</div>
<dl>
<dt>Default:</dt>
<dd>false</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="mode--">

</a>
<ul class="blockList">
<li class="blockList">
<h4>mode</h4>
<pre>public abstract&nbsp;<a href="../../../../org/springframework/context/annotation/AdviceMode.html" title="enum in org.springframework.context.annotation">AdviceMode</a>&nbsp;mode</pre>
<div class="block">Indicate how transactional advice should be applied.
<p><b>The default is <a href="../../../../org/springframework/context/annotation/AdviceMode.html#PROXY"><code>AdviceMode.PROXY</code></a>.</b>
Please note that proxy mode allows for interception of calls through the proxy
only. Local calls within the same class cannot get intercepted that way; an
<a href="../../../../org/springframework/transaction/annotation/Transactional.html" title="annotation in org.springframework.transaction.annotation"><code>Transactional</code></a> annotation on such a method within a local call will be
ignored since Spring's interceptor does not even kick in for such a runtime
scenario. For a more advanced mode of interception, consider switching this to
<a href="../../../../org/springframework/context/annotation/AdviceMode.html#ASPECTJ"><code>AdviceMode.ASPECTJ</code></a>.</div>
<dl>
<dt>Default:</dt>
<dd>org.springframework.context.annotation.AdviceMode.PROXY</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="order--">

</a>
<ul class="blockListLast">
<li class="blockList">
<h4>order</h4>
<pre>public abstract&nbsp;int&nbsp;order</pre>
<div class="block">Indicate the ordering of the execution of the transaction advisor
when multiple advices are applied at a specific joinpoint.
<p>The default is <a href="../../../../org/springframework/core/Ordered.html#LOWEST_PRECEDENCE"><code>Ordered.LOWEST_PRECEDENCE</code></a>.</div>
<dl>
<dt>Default:</dt>
<dd>2147483647</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>


<div class="bottomNav"><a name="navbar.bottom">

</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">

</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-files/index-1.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage">Spring Framework</div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.html" title="class in org.springframework.transaction.annotation"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../org/springframework/transaction/annotation/Isolation.html" title="enum in org.springframework.transaction.annotation"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/springframework/transaction/annotation/EnableTransactionManagement.html" target="_top">Frames</a></li>
<li><a href="EnableTransactionManagement.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript">allClassesLink=document.getElementById("allclasses_navbar_bottom");if(window==top){allClassesLink.style.display="block";}else{allClassesLink.style.display="none";}</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">

</a></div>

<script>if(window.parent==window){(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create','UA-2728886-23','auto',{'siteSpeedSampleRate':100});ga('send','pageview');}</script></body>
</html>
